
package contest.dao;

import contest.dto.UserTO;
import java.sql.PreparedStatement;
import java.sql.Connection;
import contest.util.IDataSource;
import contest.util.SqlBundle;
import contest.exception.ContestDAException;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author Admin
 */
public class UserDA extends ObjectDA {

    public UserDA(IDataSource datasource, SqlBundle bundle) {
        super(datasource, bundle);
    }

    @Override
    protected String getSqlBundleName(){
        return "sql_user";
    }

    public ArrayList<UserTO> getAllUser() throws ContestDAException{
        Connection conn = null;
        ResultSet rs = null;
        PreparedStatement pre = null;
        try {
            conn = this.createConnection();
            pre = this.createPrepareStatement("getAllUser", conn);
            rs = pre.executeQuery();
            ArrayList<UserTO> list = new ArrayList<UserTO>();
            while (rs.next()) {
                UserTO userTO = new UserTO();
                userTO.setID(rs.getString("ID"));
                userTO.setEmail(rs.getString("email"));
                list.add(userTO);
            }
            return list;
        }catch(Exception ex){
            throw new ContestDAException(ex.getMessage(),ex);
        }finally{
            this.close(conn, pre, rs);
        }
    }
}
